<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>登记-安平县居民核酸检测信息系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="layui/css/layui.css"  media="all">
  <script src="https://cdn.bootcdn.net/ajax/libs/fastclick/1.0.6/fastclick.js"></script>
  <script src="jquery.min.js"></script>
</head>
  <style> 
  .layui-input, .layui-textarea{width: 95%;}
  .layui-form-item .layui-form-label{text-overflow:clip;}
  /* .identity_name{display: none;} */
  .input-code{width: 55%; display: inline;}
  #send_phone{
	padding: 0;
    width: 35%;
    float: right;
    margin-right: 15px;
	font-size: 12px;
  }
  .b{
  	background-color:#cbcbcb;  
  }
  .footer{
  	text-align: center;
  	font-size: 12px;
  	color: #666666;
  	position: fixed;
  	bottom: 0;
  	width: 100%;
  }
  .footer p{
  	margin: 5px 0;
  }
  .layui-elem-quote{
	  text-align: center;
	  border-left:none;
  }
  .showModel{
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
    		z-index: 9999999999;
        }
    .modelBox{
              width: 300px;
              height: 100px;
              background-color: #ffffff;
              position: absolute;
              top: 0;
              bottom: 0;
              left: 0;
              right: 0;
              margin: auto;
			  text-align: center;
			  line-height: 100px;
      		  color:red;
          }
  </style>
<body>
          
<blockquote class="layui-elem-quote layui-text">
	为了您和家人的健康 请认真填写相关信息
</blockquote>

<form class="layui-form" action="">
  <input type="hidden" name="code" value="" />
  <div class="layui-form-item">
    <label class="layui-form-label">姓名</label>
    <div class="layui-input-block">
      <input type="text" name="name" lay-verify="required" lay-reqtext="请输入真实姓名" autocomplete="off" placeholder="请输入姓名" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">身份证号码</label>
    <div class="layui-input-block">
      <input type="text" name="idCard" lay-verify="identity" placeholder="请输入身份证号码" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">手机号</label>
    <div class="layui-input-block">
      <input type="text" name="phone" id="L_phone" lay-verify="phone" lay-reqtext="请输入手机号" placeholder="请输入手机号" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
	<div class="layui-input-block">
	  <input type="text" name="validCode" lay-verify="code" lay-reqtext="请输入验证码" placeholder="请输入验证码" autocomplete="off" class="layui-input input-code">
	  <button type="button" class="layui-btn" id="send_phone">
	  	<span id="send_str">获取验证码</span>
	  </button>
	</div>
  </div>
                              
  <div class="layui-form-item">
    <label class="layui-form-label">现住址</label>
    <div class="layui-input-block">
      <input type="text" name="address" lay-verify="required" lay-reqtext="请输入地址" placeholder="请输入地址" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  <div class="layui-form-item">
    <label class="layui-form-label">工作单位</label>
    <div class="layui-input-block">
      <input type="radio" lay-filter="identity" name="identity" value="1" title="有" checked="">
      <input type="radio" lay-filter="identity" name="identity" value="0" title="无">
    </div>
  </div>
  <div class="layui-form-item identity_name">
    <label class="layui-form-label">单位名称</label>
    <div class="layui-input-block">
      <input type="text" name="identityName" lay-verify="required2"  placeholder="请输入单位名称" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">体温</label>
    <div class="layui-input-block">
      <input type="text" name="temperature" lay-verify="required" lay-reqtext="请输入今日体温" placeholder="请输入今日体温" autocomplete="off" class="layui-input">
    </div>
  </div>
  <!--<div class="layui-form-item layui-form-text">
    <label class="layui-form-label">编辑器</label>
    <div class="layui-input-block">
      <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
    </div>
  </div>-->
  <div class="layui-form-item" style="text-align: center;">
    <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1" style="width: 200px;">检测登记</button>
  </div>
</form>
 <!--<div class="footer" style="position: absolute;">
	 <p>安平县新冠肺炎疫情防控工作指挥部</p>
	 <p>技术支持:智慧安平</p>
 </div>-->
<script src="layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'layer', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.jquery;
  
  $(document).ready(function(){
    FastClick.attach(document.body); 
	var code = getQueryVariable('code');
    if(code){
      	$('input[name="code"]').val(code);
	}else{
		window.location.href = 'http://user.city1000.top/wechat/redirect';
	}
  });
  
  //自定义验证规则
  form.verify({
	phone: [/^1[3456789]\d{9}$/, "请输入正确的手机号"],
	identity: [/(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"],
	required2: function(value){
	  var identity =  $('input[name="identity"]:checked').val();
	  if(identity == 1){
		  var reg=/[\S]+/;
		  if(!reg.test(value)){
			return '请输入单位名称';
		  }
	  }
    },
	code:function(value){
		if (!value || isNaN(value)) return "请填写正确的验证码"
	}
  });
  var codeStatus = true;
  //发送验证码
  
  $('#send_phone').on('click',function(){
     //alert('1');
	  var phone = $('#L_phone').val();
	  var reg=/^1[3456789]\d{9}$/;
	  if(!reg.test(phone)){
      layer.msg('请输入正确的手机号',{icon:2});
      return false;
    }
    layer.msg('请求中...');
	  if(codeStatus){
        codeStatus = false;
        $.ajax({
          url: 'http://user.city1000.cn:9999/hesuan/api/v1/sms/hsVerificationCode',
          type: 'POST',
          dataType: "json",
          data: {
            'phone':phone
          },
          success: function(res){
            if(res.code == 0){
              console.log(res.code)
              var setTime;
              var time=60;
              setTime=setInterval(function(){
                if(time==0){
                      clearInterval(setTime);
                      codeStatus = true;
                      $("#send_phone").removeClass("b");
                      $("#send_str").text("获取验证码");
                      return;
                  }else{
                      $("#send_phone").addClass("b");
                      $("#send_str").text(time+"s后重新获取");
                  }
                  time--;
              },1000);	
            }else{
              codeStatus = true;
              layer.msg(res.msg,{icon:2});
            }
          }
        });
        // $.post('http://user.city1000.cn:9999/hesuan/api/v1/sms/hsVerificationCode',{phone:phone},function(res){
        //     console.log(res.code)
            
        // }) 
	  }
  })
  
  //监听单选框
  form.on('radio(identity)', function (data) {
  　　console.log( data );　　//打印当前选择的信息
	  if(data.value == 1){
		  $('.identity_name').show();
	  }else{
		  $('.identity_name').hide();
	  }
	  form.render();
  });
  
  //监听提交
  form.on('submit(demo1)', function(data){
	var loadIndex;
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
	$.ajax({
		url: 'http://user.city1000.cn:9999/hesuan/hsUser/insert',
		data: data.field,
		beforeSend:function(){
			loadIndex = layer.load(1, { shade: [0.3, 'rgb(0, 0, 0)'] })
		},
		success: function (res) {
			//console.log(res)
			if(res.code == 0){
				layer.msg('登记成功，即将跳转首页！', {icon:1,time:2000},function(){
					window.location.href='http://api.city1000.cn:9999/weixin/wechat/h5/redirectSomeWhere?url=http://hesuan.city1000.cn'
				});
			}else{
              	//alert(res.msg);
				//layer.msg(res.msg,{icon:2});
              	layer.msg(res.msg, {icon:2,time:2000},function(){
					window.location.href='http://user.city1000.top/wechat/redirect';
				});
			}
		},
      	error: function(){
    		layer.msg('当前人数较多，请稍后再试',{icon:2});
  		},
		complete:function(){
			layer.close(loadIndex); 
		}
	});
	return false;
  });
  
});
function getQueryVariable(variable)
{
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}
</script>

</body>
</html>